package com.sg.web;

import com.sg.bean.Order;
import com.sg.service.ComandOrderService;
import com.sg.service.OrderService;
import com.sg.vo.BusinessVO;
import com.sg.vo.ComandOrderVO;
import com.sg.vo.OrderVO;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author wangcf
 * @Description
 * @date 2023/3/17 9:21
 */
@Controller
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private ComandOrderService comandOrderService;
    Logger logger = Logger.getLogger(OrderController.class);

    @RequestMapping("thirdly/businessorderlist")
    public String orderlist(HttpSession session, Model model) {
        logger.info("进入到商家的订单列表");
        Object obj = session.getAttribute("business");
        BusinessVO businessVO = (BusinessVO) obj;
        List<OrderVO> orderVOS = orderService.findBusinessId(businessVO.getBusinessId());
        model.addAttribute("businessorderlist", orderVOS);
        return "thirdly/businessorderlist";
    }

    @RequestMapping("thirdly/businessorderupdate")
    public String businessorderupdate(int orderId, int osId) {
        Order order = orderService.findById(orderId);
        order.setOsId(osId);
        boolean i = orderService.update(order);
        return "redirect:businessorderlist.action";
    }

    @RequestMapping("thirdly/comandorderlist")
    public String comandorderlist(int orderId,Model model) {
        List<ComandOrderVO> comandOrderVOS=comandOrderService.findList(orderId);
        model.addAttribute("comandorderlist",comandOrderVOS);
        return "thirdly/comandorderlist";
    }
}
